package com.smallrig.mall.template.event;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.GenericApplicationListener;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.stereotype.Component;


@Component
public class AEventListener3 implements GenericApplicationListener {

//AnnotationAwareOrderComparator.sort(List<Object>); 对spring 实现order接口，@Order注解进行排序
//ResolvableType 这个api很有用，处理泛型等很方便
    // 父类.isAssignableFrom(子类)
    //ClassUtils,AopUtils,ReflectionUtils，AnnotatedElementUtils
//org.springframework.statemachine.processor.StateMachineAnnotationPostProcessor.postProcessAfterInitialization
    @Override
    public int getOrder() {
        return GenericApplicationListener.super.getOrder();
    }

    @Override
    public boolean supportsSourceType(Class<?> sourceType) {

        return GenericApplicationListener.super.supportsSourceType(sourceType);
    }

    @Override
    public boolean supportsEventType(ResolvableType eventType) {
        return TestEvent.class.equals(eventType.getRawClass());
    }

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        System.out.println(Thread.currentThread().getName()+" "+event);
    }
}
